home *** CD-ROM | disk | FTP | other *** search
- Path: tudelft.nl!news
- From: Ejo Schrama <schrama@geo.tudelft.nl>
- Newsgroups: comp.lang.c++
- Subject: Re: A garbage collection problem in C++
- Date: 15 Mar 1996 15:58:52 GMT
- Organization: TU Delft, Faculty of Geodetic Engineering
- Message-ID: <4ic43s$k0@mo6.rc.tudelft.nl>
- References: <4ic3vb$k0@mo6.rc.tudelft.nl>
- NNTP-Posting-Host: dutgs7.geo.tudelft.nl
- Mime-Version: 1.0
- Content-Type: multipart/mixed;
- boundary="-------------------------------263031712011091"
- X-Mailer: Mozilla 1.12 (X11; I; HP-UX A.09.05 9000/735)
- X-URL: file:/users/schrama/work/dingo/work/test.cc
-
- This is a multi-part message in MIME format.
-
- ---------------------------------263031712011091
- Content-Transfer-Encoding: 7bit
- Content-Type: text/plain; charset=us-ascii
-
- Ejo Schrama <schrama@geo.tudelft.nl> wrote:
- >This is a multi-part message in MIME format.
- >
- >---------------------------------9580122325627
- >Content-Transfer-Encoding: 7bit
- >Content-Type: text/plain; charset=us-ascii
- >
- >I noticed a garbage collection problem with the following program.
- >If you decide to delete arrays then we all know that
- >
- > double *a;
- > a = new double[1000];
- > delete[] a;
- >
- >works. However the following code shows that the delete[] operator
- >will only treat the first argument as an array, the second argument
- >is not. It sounds like a easter-egg....
- >
- >Ejo (http://www.geo.tudelft.nl/fmr/people/schrama.html)
- >
-
- I rather had the following code in mind, forget previous posting
-
- ---------------------------------263031712011091
- Content-Transfer-Encoding: 7bit
- Content-Type: text/plain
-
- #include <stdio.h>
- #include <stdlib.h>
-
- main()
- {
- double *a,*b;
- a = new double[1000];
- b = new double[1000];
- //
- // OPTION1: causes 8008 bytes of garbage on the heap
- //
- #ifdef OPTION1
- delete[] a,b;
- #endif
- //
- // OPTION2: cleans up the heap
- //
- #ifdef OPTION2
- delete[] a;
- delete[] b;
- #endif
- //
- // Under HP-UX the following will show a memory map
- //
- memorymap(0);
- }
-
- ---------------------------------263031712011091--
-